//
//  ChallengeAlert.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/30.
//

#import "ChallengeAlert.h"
#import "CommonUtil.h"
#import "LineBtnView.h"
@interface ChallengeAlert()
@property (strong, nonatomic) UILabel * titleLabel;
@property (strong, nonatomic) UIView * lineView;
@property (strong, nonatomic) LineBtnView * timeView;
@property (strong, nonatomic) LineBtnView * difficultyView;
@property (strong, nonatomic) LineBtnView * levelView;
@property (strong, nonatomic) LineBtnView * rewardView;

@property (strong, nonatomic) UIButton * cancelBtn;
@property (strong, nonatomic) UIButton * ruleBtn;
@property (strong, nonatomic) UIButton * joinBtn;
@end

@implementation ChallengeAlert


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.whiteView];
        self.whiteView.layer.cornerRadius = AD(10);
        self.whiteView.clipsToBounds = YES;
        
    }
    return self;
}


-(void)show{
    self.whiteView.frame = CGRectMake(AD(10), 0, SCREEN_WIDTH-AD(20), AD(360));
    self.whiteView.centerY = SCREEN_HEIGHT/2;
    
    [self.whiteView addSubview:self.titleLabel];
    [self.whiteView addSubview:self.lineView];
    [self.whiteView addSubview:self.timeView];
    [self.whiteView addSubview:self.difficultyView];
    [self.whiteView addSubview:self.levelView];
    [self.whiteView addSubview:self.rewardView];
    
    [self.whiteView addSubview:self.cancelBtn];
    [self.whiteView addSubview:self.ruleBtn];
    [self.whiteView addSubview:self.joinBtn];
    
}

- (void)btnClick:(UIButton *)sender{
    if (self.actionBlock) {
        NSArray *arr = @[self.timeView.selectBtn.titleLabel.text,self.difficultyView.selectBtn.titleLabel.text,self.levelView.selectBtn.titleLabel.text,self.rewardView.selectBtn.titleLabel.text];
        
        self.actionBlock(arr);
    }
    [self dismiss];
}

#pragma mark - lazy
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.whiteView.width, AD(50))];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:AD(18)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"三肖";
    }
    return _titleLabel;
}

-(UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.bottom, self.whiteView.width, AD(1))];
        _lineView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    }
    return _lineView;
}

-(LineBtnView *)timeView{
    if (!_timeView) {
        _timeView = [[LineBtnView alloc] initWithFrame:CGRectMake(0, _lineView.bottom, self.whiteView.width, AD(60))];
        _timeView.type = @"挑战周期";
    }
    return _timeView;
}

-(LineBtnView *)difficultyView{
    if (!_difficultyView) {
        _difficultyView = [[LineBtnView alloc] initWithFrame:CGRectMake(0, _timeView.bottom, self.whiteView.width, AD(60))];
        _difficultyView.type = @"挑战难度";
    }
    return _difficultyView;
}
-(LineBtnView *)levelView{
    if (!_levelView) {
        _levelView = [[LineBtnView alloc] initWithFrame:CGRectMake(0, _difficultyView.bottom, self.whiteView.width, AD(60))];
        _levelView.type = @"挑战级别";
    }
    return _levelView;
}
-(LineBtnView *)rewardView{
    if (!_rewardView) {
        _rewardView = [[LineBtnView alloc] initWithFrame:CGRectMake(0, _levelView.bottom, self.whiteView.width, AD(60))];
        _rewardView.type = @"可得奖励";
    }
    return _rewardView;
}
    
-(UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        [_cancelBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _cancelBtn.layer.cornerRadius = AD(5);
        _cancelBtn.clipsToBounds = YES;
        _cancelBtn.frame = CGRectMake(AD(10),_rewardView.bottom + AD(15), (self.whiteView.width-AD(50))/3, AD(40));
        _cancelBtn.backgroundColor = RGB(182.0, 182.0, 182.0);
    }
    return _cancelBtn;
}

-(UIButton *)ruleBtn{
    if (!_ruleBtn) {
        _ruleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_ruleBtn setTitle:@"规则" forState:UIControlStateNormal];
        [_ruleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _ruleBtn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        [_ruleBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _ruleBtn.layer.cornerRadius = AD(5);
        _ruleBtn.clipsToBounds = YES;
        _ruleBtn.frame = CGRectMake(_cancelBtn.right + AD(15),_rewardView.bottom + AD(15), _cancelBtn.width, AD(40));
        _ruleBtn.backgroundColor = RGB(81.0, 172.0, 211.0);
    }
    return _ruleBtn;
}

-(UIButton *)joinBtn{
    if (!_joinBtn) {
        _joinBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_joinBtn setTitle:@"参加" forState:UIControlStateNormal];
        [_joinBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _joinBtn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        [_joinBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _joinBtn.layer.cornerRadius = AD(5);
        _joinBtn.clipsToBounds = YES;
        _joinBtn.frame = CGRectMake(_ruleBtn.right + AD(15),_rewardView.bottom + AD(15), _cancelBtn.width, AD(40));
        _joinBtn.backgroundColor = RGB(236.0, 92.0, 77.0);
    }
    return _joinBtn;
}



@end
